package com.example.demo;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 用于生成二维码和简单访问对应的链接
 * @author: LiuYC
 * @date: 2021年04月21日 15:25
 */
@RestController
public class QrcodeController {
    @Resource
    ExamMapper examMapper;

    @RequestMapping("/createQrcode/{name}")
    public String createQrcode(@PathVariable("name") String name) {
        System.out.println("输出的name：");
        System.out.println(name);
//        工具类生成：
        String s = PswUtil.PswUtils();
        String http = "http://localhost:19999/getExam/";
//        更新数据库
        Exam exam = new Exam();
        exam.setA("a");
        exam.setExamId(s);
        exam.setId("3");
        exam.setHead("题目是test");
        exam.setContent("内容是：如何进行测试方案的编写");
        examMapper.insert(exam);
        System.out.println("插入数据库完成：");
//        返回值到前端
        return http + s;
    }

    @RequestMapping("/getExam/{name}")
    public Exam getExam(@PathVariable("name") String name) {
        ExamExample examExample = new ExamExample();
        examExample.createCriteria().andExamIdEqualTo(name);
        List<Exam> exams = examMapper.selectByExample(examExample);
        if (exams.isEmpty()) {
            return null;
        }
        return exams.get(0);
    }
}
